package com.lee.blog.listener;

import com.lee.blog.service.TimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

@WebListener
@Component
public class RequestListener implements HttpSessionListener {

    @Autowired
    TimeService timeService;


    @Override
    public void sessionCreated(HttpSessionEvent se) {
        String id = se.getSession().getId();
        System.out.println("session创建 : " + id);
        int uv = timeService.getUv();
        uv += 1;
        timeService.setUv(uv);
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        System.out.println("Session销毁");
    }
}
